home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / Python 1.3 PPC / Tools / bgen / list / tlist.py < prev   
Encoding:
Python Source  |  1995-10-11  |  2.2 KB  |  95 lines  |  [TEXT/PYTH]

  1. # Test List module.
  2. # Draw a window with all the files in the current folder.
  3. # double-clicking will change folder.
  4. #
  5. # This test expects Win, Evt and FrameWork (and anything used by those)
  6. # to work.
  7. #
  8. # Actually, it is more a test of FrameWork by now....
  9.  
  10. from FrameWork import *
  11. import Win
  12. import Qd
  13. import List
  14. import os
  15.  
  16. class ListWindow(Window):
  17.     def open(self, name, where):
  18.         self.where = where
  19.         r = (40, 40, 400, 300)
  20.         w = Win.NewWindow(r, name, 1, 0, -1, 1, 0x55555555)
  21.         r2 = (0, 0, 345, 245)
  22.         self.list = List.LNew(r2, (0, 0, 1, 1), (0,0), 0, w, 0, 1, 1, 1)
  23.         self.filllist()
  24.         w.DrawGrowIcon()
  25.         self.wid = w
  26.         self.do_postopen()
  27.         
  28.     def do_activate(self, onoff, evt):
  29.         self.list.LActivate(onoff)
  30.  
  31.     def do_rawupdate(self, window, event):
  32.         window.BeginUpdate()
  33.         self.do_update(window, event)
  34.         window.EndUpdate()
  35.         
  36.     def do_update(self, *args):
  37.         self.list.LUpdate()
  38.         
  39.     def do_contentclick(self, local, modifiers, evt):
  40.         dclick = self.list.LClick(local, modifiers)
  41.         if dclick:
  42.             h, v = self.list.LLastClick()
  43.             file = self.list.LGetCell(1000, (h, v))
  44.             self.where = os.path.join(self.where, file)
  45.             self.filllist()
  46.  
  47.     def filllist(self):
  48.         """Fill the list with the contents of the current directory"""
  49.         l = self.list
  50.         l.LSetDrawingMode(0)
  51.         l.LDelRow(0, 0)
  52.         contents = os.listdir(self.where)
  53.         l.LAddRow(len(contents), 0)
  54.         for i in range(len(contents)):
  55.             l.LSetCell(contents[i], (0, i))
  56.         l.LSetDrawingMode(1)
  57.         l.LUpdate()
  58.  
  59.  
  60. class TestList(Application):
  61.     def __init__(self):
  62.         Application.__init__(self)
  63.         self.num = 0
  64.         self.listoflists = []
  65.         
  66.     def makeusermenus(self):
  67.         self.filemenu = m = Menu(self.menubar, "File")
  68.         self.newitem = MenuItem(m, "New window...", "O", self.open)
  69.         self.quititem = MenuItem(m, "Quit", "Q", self.quit)
  70.     
  71.     def open(self, *args):
  72.         import macfs
  73.         fss, ok = macfs.GetDirectory()
  74.         if not ok:
  75.             return
  76.         w = ListWindow(self)
  77.         w.open('Window %d'%self.num, fss.as_pathname())
  78.         self.num = self.num + 1
  79.         self.listoflists.append(w)
  80.         
  81.     def quit(self, *args):
  82.         raise self
  83.  
  84.     def do_about(self, id, item, window, event):
  85.         EasyDialogs.Message("""Test the List Manager interface.
  86.         Simple inward-only folder browser""")
  87.  
  88. def main():
  89.     App = TestList()
  90.     App.mainloop()
  91.     
  92. if __name__ == '__main__':
  93.     main()
  94.     
  95.